from utilities import *
from toee import *

def san_heartbeat( attachee, triggerer ):
	if (attachee.map == 5001):
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (641L, 387L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (714L, 381L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (573L, 424L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (617L, 460L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (592L, 485L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (454L, 442L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (472L, 313L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (418L, 378L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		if (game.random_range(1,3) == 1):
			barrel = game.obj_create( 1049, location_from_axis (364L, 406L) )
			if (game.random_range(1,3) <= 2):
				create_item_in_inventory( 5007, barrel )
		game.global_vars[766] = game.random_range(1,20)
		attachee.destroy()
	if (attachee.map == 5080):
		game.global_vars[707] = game.global_vars[707] + 1
	if (attachee.map == 5080 and game.global_vars[707] >= 3 and game.global_flags[820] == 0):
		game.global_vars[707] = 0
		game.particles( 'sp-Call Lightning', attachee )
		game.sound(4019,1)
		for obj in game.obj_list_vicinity( attachee.location, OLC_CRITTERS ):
			if (obj.distance_to(attachee) <= 12 and obj.name != attachee.name and obj.name != 14605):
				game.particles( 'sp-Shocking Grasp', obj )
				game.sound(4030,1)
				if (obj.stat_level_get( stat_hp_current ) >= -9):
#					loc = obj.location
#					loc = loc - 1
#					obj.turn_towards(loc)
					for chest in game.obj_list_vicinity(attachee.location,OLC_CONTAINER):
						if (chest.name == 1055):
							if (obj.has_los(chest)):	
								obj.turn_towards(chest)
#					obj.begin_dialog(attachee,1)
#					obj.condition_add_with_args( 'sp-Hold Person', 0, 1, 0 )
#					obj.condition_add_with_args( 'prone', 0, 0)
					damage_dice = dice_new( '15d4' )
					if (obj.name == 8035):
						damage_dice = dice_new('5d4')
					if obj.reflex_save_and_damage( OBJ_HANDLE_NULL, 20, D20_Save_Reduction_Half, D20STD_F_NONE, damage_dice, D20DT_ELECTRICITY, D20DAP_UNSPECIFIED, 0 , D20DAP_NORMAL ):
#						saving throw successful
						obj.float_mesfile_line( 'mes\\spell.mes', 30001 )
					else:
#						saving throw unsuccessful
						obj.float_mesfile_line( 'mes\\spell.mes', 30002 )
#					obj.damage( OBJ_HANDLE_NULL, D20DT_ELECTRICITY, damage_dice, D20DAP_NORMAL)

	return RUN_DEFAULT

